import sys
from PyQt5.QtWidgets import (
    QApplication,
    QMessageBox,
    QWidget,
    QPushButton,
    QRadioButton,
    QButtonGroup,
)


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.init_UI()
        self.info1 = ""
        self.info2 = ""

    def init_UI(self):
        self.resize(300, 300)
        self.setWindowTitle("单选按钮")
        self.rb11 = QRadioButton("你是", self)
        self.rb11.move(20, 20)
        self.rb12 = QRadioButton("我是", self)
        self.rb12.move(20, 40)
        self.rb13 = QRadioButton("他是", self)
        self.rb13.move(20, 60)

        self.rb21 = QRadioButton("大美女", self)
        self.rb21.move(80, 20)
        self.rb22 = QRadioButton("大帅哥", self)
        self.rb22.move(80, 40)
        self.rb23 = QRadioButton("小屁孩", self)
        self.rb23.move(80, 60)

        self.bg1 = QButtonGroup(self)
        self.bg2 = QButtonGroup(self)

        self.bg1.addButton(self.rb11, 11)
        self.bg1.addButton(self.rb12, 12)
        self.bg1.addButton(self.rb13, 13)

        self.bg2.addButton(self.rb21, 21)
        self.bg2.addButton(self.rb22, 22)
        self.bg2.addButton(self.rb23, 23)

        bt1 = QPushButton("提交", self)
        bt1.move(20, 100)

        # self.bg1.button(11).setChecked(True)

        self.bg1.buttonToggled.connect(self.rbclicked)
        # self.bg2.buttonClicked.connect(self.rbclicked)

        # bt1.clicked.connect(self.submit)

        self.show()

    # def submit(self):
    #     if self.info1 == "" or self.info2 == "":
    #         QMessageBox.information(self, "What?", "貌似有没有选的啊，快去选一个吧！")
    #     else:
    #         QMessageBox.information(self, "What?", self.info1 + self.info2)

    def rbclicked(self):

        # self.bg1.setExclusive(False)
        if self.bg1.button(11).isCheckable():

            self.bg1.button(11).setChecked(False)
        # self.bg1.setExclusive(True)

        # self.bg1.button(11).setCheckable(True)
        # if checked:
        #     self.bg1.setExclusive(False)
        #     self.bg1.button(11).setChecked(False)
        #     self.bg1.setExclusive(True)

        # sender = self.sender()
        # if sender == self.bg1:
        #     if self.bg1.checkedId() == 11:
        #         self.info1 = "你是"

        #     elif self.bg1.checkedId() == 12:
        #         self.info1 = "我是"
        #     elif self.bg1.checkedId() == 13:
        #         self.info1 = "他是"
        #     else:
        #         self.info1 = ""


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
